/* eslint-disable @typescript-eslint/no-unused-vars */
import { request } from '@umijs/max';
import { AnyKindOfDictionary } from 'lodash';
export const loadDataAPI = async (
  // 第一个参数 params 查询表单和 params 参数的结合
  // 第一个参数中一定会有 pageSize 和  current ，这两个参数是 antd 的规范
  params: any & {
    pageSize: number;
    current: number;
  },
  //@ts-ignore
  sort,
  //@ts-ignore
  filter,
) => {
  // 这里需要返回一个 Promise,在返回之前你可以进行数据转化
  // 如果需要转化参数可以在这里进行修改
  // const msg = await myQuery({
  //   page: params.current,
  //   pageSize: params.pageSize,
  // });
  console.log(params);
  const { pageSize, current, ...others } = params;
  const res = await request('/admin/users', {
    params: {
      ...others,
      page: params.current,
      per: params.pageSize,
    },
  });
  return {
    data: res.data.list, //数据
    // success 请返回 true，
    // 不然 table 会停止解析数据，即使有数据
    success: true,
    // 不传会使用 data 的长度，如果是分页一定要传
    total: res.data.total,
  };
};

export const addDoctorAPI = (data: any) => {
  return request('/admin/users', {
    method: 'POST',
    data,
  });
};

export const delDoctorAPI = (id: any) => {
  return request('/admin/users/' + id, {
    method: 'DELETE',
  });
};

export const loadDoctorAPI = (id: any) => {
  return request('/admin/users/' + id, {
    method: 'GET',
  });
};

export const editDoctorAPI = (id: any, data: any) => {
  return request('/admin/users/' + id, {
    method: 'PATCH',
    data,
  });
};

export const delusersAPI = (ids: any) => {
  return request('/admin/users/remove_many/', {
    params: {
      ids,
    },
    method: 'DELETE',
  });
};

//权限列表

export const loadperAPI = () => {
  return request('/admin/permissions');
};

//重置密码
export const resetAPI = (id: any, data: any) => {
  return request('/admin/users/reset_pwd/' + id, {
    method: 'PATCH',
    data,
  });
};

export const roleListAPI = () => {
  return request('/admin/roles');
};
